package com.yhb.myshop.web.admin.web.controller;

import com.yhb.myshop.domain.TbCategory;
import com.yhb.myshop.web.admin.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/category")
public class CategoryController extends BaseController<TbCategory,CategoryService> {

    @Override
    public String list(Model model) {
        List<TbCategory> categories= service.getAll();
        model.addAttribute("categories",categories);

        return super.list(model);
    }

    @ResponseBody
    @RequestMapping(value = "/tree/data")
    public List<TbCategory> treeData() {

        return service.getAll();
    }
    @Override
    protected TbCategory initFormEntity() {
        return new TbCategory();
    }


}
